package com.czh.controller;

import com.czh.mapper.ArticleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class IndexController {

    @Autowired
    private ArticleMapper articleMapper;

    @RequestMapping("/index")
    public String toIndex(@RequestParam(value = "page", required = false) Integer page, Model model) {
        Integer finalPage = page;
        if (finalPage == null) {
            finalPage = 1;
        }

        model.addAttribute("articleList", articleMapper.selectPage(finalPage - 1));

        Integer total = articleMapper.selectCount();
        model.addAttribute("totalPage", total);
        model.addAttribute("currentPage", finalPage);

        return "client/index";
    }


}
